package com.zm.tools.validate.core;

/**
 * Description: 中英文、数字、下划线正则验证
 * Created by zoum on 2018/6/6 15:59
 */
public class ChineseEngLishNumberUnderLineValidator extends BaseValidator {

    /**
     * 不限制长度 验证中英文、数字、下划线
     * @param s
     * @return
     */
    public static boolean validate(String s) {
        String regex = "^(\\w|[\u4e00-\u9fa5])*$";
        return validate(s, regex);
    }

    /**
     * 固定长度 验证中英文、数字、下划线
     * @param s
     * @param digit
     * @return
     */
    public static boolean validate(String s, int digit) {
        String regex = "^(\\w|[\u4e00-\u9fa5]){" + digit + "}$";
        return validate(s, regex);
    }

    /**
     * 范围长度 验证中英文、数字、下划线
     * @param s
     * @param minDigit
     * @param maxDigit
     * @return
     */
    public static boolean validate(String s, int minDigit, int maxDigit) {
        String regex = "^(\\w|[\u4e00-\u9fa5]){" + minDigit + "," + maxDigit + "}$";
        return validate(s, regex);
    }

}
